<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/in.jsp"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="zh-CN">
<head>
    <meta name="viewport" content="width=device-width,initial-scale=1,user-scalable=0">
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>个人信息</title>
    <link rel="stylesheet" href="${staticPage}/css/weui.css"/>
    <link rel="stylesheet" href="${staticPage}/css/myInfo.css"/>
    <!--<link rel="stylesheet" href="css/example.css"/>-->
</head>
<script type="text/javascript">
	var isChange=false;    //是否更改信息
 	var isChangeTel=false;    //是否更换手机号
 	var isGetCode=false;   //是否获取验证码
//  	var oldTel=${current_user.tel}; //保存旧的手机号 
 	
	var countdown=60; 
	
	function settime(val) { 
		if (countdown == 0) { 
			val.removeAttr("disabled");   
			val.css("background-color","#02c69e")
			val.val("获取"); 
			countdown = 60; 
			return false;
		} else { 
			val.attr("disabled", "disabled"); 
			val.css("background-color","#adaead")
			val.val(countdown + "秒"); 
			countdown--; 
		} 
		setTimeout(function() { 
		settime(val) 
		},1000) 
	} 
 	function showToast(){
		 $('#toast').show();
        setTimeout(function () {
            $('#toast').hide();
            window.location.reload();
        }, 2000);
	}
 	//获取个人信息
	function getUserInfo(){
		$.getJSON("${ctx}/user_getUserInfo.json",function(json){
			if(json.success){
				switch (json.dot)
				{
				
				case 401:
				  $("#dot").html("金牛支行营业室（沙湾路）");
				  break;
				case 402:
					$("#dot").html("成都花园支行（青羊大道）");
				  break;
				case 403:
					$("#dot").html("荷花池支行（金牛万达旁）");
				  break;
				case 404:
					$("#dot").html("外西支行（花牌坊北街）");
				  break;
				case 405:
					$("#dot").html("天回支行（天回镇上街）");
				  break;
				case 406:
					$("#dot").html("高笋塘支行（二环路北三段）");
				  break;
				case 407:
					$("#dot").html("西郊支行（十二桥路）");
				  break;
				case 408:
					$("#dot").html("洞子口支行（洞子口）");
				  break;
				case 409:
					$("#dot").html("蜀鑫支行（蜀鑫路）");
				  break;
				case 410:
					$("#dot").html("蜀西支行（蜀西路）");
				  break;
				case 411:
					$("#dot").html("五福支行（蓉北商贸大道）");
				  break;
				case 412:
					$("#dot").html("茶店子支行（茶店子东街）");
				  break;
				case 413:
					$("#dot").html("国际商贸城支行（国际商贸城）");
				  break;
				case 414:
					$("#dot").html("光华逸家分理处（万家湾光华逸家小区）");
				  break;
				case 415:
					$("#dot").html("大湾分理处（军区总医院内）");
				  break;
				case 416:
					$("#dot").html("蜀汉路支行（蜀蓉路）");
				  break;
				case 417:
					$("#dot").html("星辰支行（九里堤星辰路）");
				  break;
				}
				if(json.name==""||json.name==null){
					$("#name").html("待填写");
				}
				else{
					$("#name").html(json.name);
				}
				if(json.birth==""||json.birth==null){
					$("#birth").html("待填写");
				}
				else{
					$("#birth").html(json.birth);
				}
				/* if(json.sex==""||json.sex==null){
					$("#sex").html("待填写");
					console.log("sex为空");
				}
				else{
					if(json.sex==0)
					$("#sex").html("男");
					else
					$("#sex").html("女");
				} */
				switch (json.sex)
				{
					case 0:
						$("#sex").html("男");
					  break;
					case 1:
						$("#sex").html("女");
					  break;
					 default:
						$("#sex").html("待填写");
				}
				if(json.tel==""||json.tel==null){
					$("#tel").html("待填写");
				}
				else{
					$("#tel").html(json.tel);
				}
				
				
				
				
				
				
			}
			else{
				alert(json.msg);
			}
				
		})	
 	}
	
	$(function(){
		//获取个人信息
		getUserInfo();
		//添加网点内容
		/* $("select[name='dot']").val("${current_user.dot}"); */
		
		
		
		$("#modifyButton").click(function(){
			isChange=true;
			$("input[name='realname']").removeAttr("disabled");
			$("input[name='birth']").removeAttr("disabled");
			$("input[name='tel']").removeAttr("disabled");
			
			$("#changeTel").css("display","")			
		});
		
// 		$("#changeTel").click(function(){
// 			isChangeTel=true;
// 			$("input[name='tel']").removeAttr("disabled");
// 			$("input[name='tel']").val("");
// 			$("#validateCode").css("display","");
// 		});
		
		$("#saveButton").click(function(){
			
			var realname=$("input[name='realname']").val();
			var tel=$("input[name='tel']").val();
			var birth=$("input[name='birth']").val();
// 			var code=$("input[name='code']").val();
// 			var sessionId=$("input[name='sessionId']").val();
			if(isChange){

					if(realname==""&&tel==""&&birth==""){
						 if(birth==""){
								alert("生日不能为空！");
							}
							else if(realname==""){
								alert("姓名不能为空！");
							}
							else if(tel==""){
								alert("更换手机号不能为空！");
							}

					}
					else{
							$.getJSON("${ctx}/user_modifyInfo.json",
									{name:realname,birth:birth,tel:tel},
							function(json){
								if(json.success){
									showToast();
								}
								else{
									alert(json.msg);
									}
							})
					}
				}
			
						 
			
		});
		//获取验证码
// 		$("#getCode").click(function(){
// 			isGetCode=true;
// 			if(oldTel==$("input[name='tel']").val()){
// 				alert("新手机号不能与之前的手机号相同！");
// 			}
// 			else{
// 				$.getJSON("${ctx}/user_sendMessage.json",
// 						{tel:$("#resggister_form  input[name='tel']").val()},
// 				function(json){
// 					if(json.success){
// 						alert("短信验证码发送成功！");
// 						settime($("#getCode"));
// 						$("input[name='sessionId']").val(json.sessionId);
// 						/* $("#wxUserForm input[name='code']").val(json.code); */				
// 					}
// 					else{
// 						alert(json.msg);
// 						}
// 				})
// 			}
// 		})
			
	})

</script>
<body>
	
	<div class="weui_cells weui_cells_access">
        <a class="weui_cell" href="${staticPage}/modifyName.do">
            <div class="weui_cell_bd weui_cell_primary">
                <p>姓名</p>
            </div>
            <div class="weui_cell_ft " id="name">${current_user.realname}</div>
        </a>
        
         <a class="weui_cell" href="${staticPage}/modifyTel.do">
            <div class="weui_cell_bd weui_cell_primary">
                <p>手机号</p>
            </div>
            <div class="weui_cell_ft" id="tel">${current_user.tel}</div>
        </a>
        <a class="weui_cell" href="${staticPage}/modifySex.do">
            <div class="weui_cell_bd weui_cell_primary">
                <p>性别</p>
            </div>
            <div class="weui_cell_ft" id="sex"></div>
        </a>
         <a class="weui_cell" href="${staticPage}/modifyBirth.do">
            <div class="weui_cell_bd weui_cell_primary">
                <p>生日</p>
            </div>
            <div class="weui_cell_ft" id="birth"></div>
        </a>
        

    </div>
    
    <div class="weui_cells" style="margin-top:0px !important">
		<a class="weui_cell" >
            <div class="weui_cell_bd weui_cell_primary">
                <p>网点</p>
            </div>
            <div class="weui_cell_ft" id="dot"></div>
        </a>
	</div>
      
</body>
</html>